const redis = require('../redis')
async function main(ctx){
    //判断用户是否登陆，未登录则返回444
    const username = ctx.username
    if (username) {
        if (global.config.redisOn){ //redis
            await redis.connect()
            let user = await redis.get(username)
            user = JSON.parse(user)
            if (user) return user
        }else{ //mysql
            const sql = `select * from sys_user where username='${username}'`
            const rs = await global.query(sql)
            if (rs.length === 1) return rs[0]
        }
    }
    return false
}

module.exports = main